<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>入党申请</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/resources/css/public.css" media="all" />
</head>
<body class="childrenBody">
<!-- 查询条件开始-->

<!-- 查询条件结束-->


<!-- 数据表格开始 -->
<div>
    <table class="layui-hide" id="customerTable" lay-filter="customerTable"></table>
    <!-- 工具栏 -->
    <div id="customerToolBar" style="display: none;">
        <button type="button" lay-event="addLevel1" class="layui-btn layui-btn-sm layui-btn-radius" shiro:hasPermission="customer:create"><span class="layui-icon layui-icon-add-1"></span>提交入党积极分子申请</button>
        <button type="button" lay-event="addLevel2" class="layui-btn layui-btn-sm layui-btn-radius" shiro:hasPermission="customer:create"><span class="layui-icon layui-icon-add-1"></span>提交预备党员申请</button>
        <button type="button" lay-event="addLevel3" class="layui-btn layui-btn-sm layui-btn-radius" shiro:hasPermission="customer:create"><span class="layui-icon layui-icon-add-1"></span>提交正式党员申请</button>
        <button type="button" lay-event="pay" class="layui-btn layui-btn-sm layui-btn-radius" shiro:hasPermission="customer:pay"><span class="layui-icon layui-icon-add-1"></span>缴费</button>
    </div>

</div>
<!-- 数据表格结束 -->

<!-- 添加和修改的弹出层开始 -->

<div  style="display: none;padding: 5px" id="addOrUpdateDiv">
    <form class="layui-form" style="width:80%;" id="dataFrm" lay-filter="dataFrm">
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">学号</label>
            <div class="layui-input-block">
                <input type="hidden" name="level" id="level">
                <input type="text" class="layui-input" name="custno"  lay-verify="required" placeholder="请输入学号">
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block">

                <input type="text" class="layui-input" name="custname"  lay-verify="required" placeholder="请输入名称">
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">思想汇报</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="reason"  lay-verify="required" placeholder="请输入思想汇报">
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">学习小结</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="study"  lay-verify="required" placeholder="请输入学习小结">
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="remark"  lay-verify="required" placeholder="请输入备注">
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-xs12">
            <div class="layui-input-block" style="text-align: center;">
                <button type="button" class="layui-btn layui-btn-radius" lay-submit lay-filter="doSubmit" ><span class="layui-icon layui-icon-add-1"></span>提交</button>
                <button type="reset" class="layui-btn layui-btn-warm layui-btn-radius"><span class="layui-icon layui-icon-refresh-1"></span>重置</button>
            </div>
        </div>
    </form>
</div>

<!-- 添加和修改的弹出层结束 -->

<script type="text/javascript" src="/resources/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['jquery','form','table','layer','laydate'],function () {
        var $=layui.jquery;
        var form=layui.form;
        var table=layui.table;
        var layer=layui.layer;
        var laydate=layui.laydate;

        //渲染表格
        var tableIns = table.render({
            elem: '#customerTable'//绑定表格组件的id
            , toolbar: '#customerToolBar'
            , height: 'full-110'
            , title: ''
            , url: '/customer/customerOneList/' //数据接口
            , page: true //开启分页
            , cols: [ [
                {type: 'checkbox', fixed: 'left'}
                , {field: 'custname', title: '名称', align: 'center'}
                , {field: 'custno', title: '学号', align: 'center'}
                , {field: 'reason', title: '思想汇报', align: 'center'}
                , {field: 'reason', title: '学习小结', align: 'center'}
                , {field: 'reason', title: '思想汇报', align: 'center'}
                , {field: 'time', title: '申请时间', align: 'center'}
                , {field: 'status', title: '支部审核结果', align: 'center',templet:function (d) {
                        if(d.status==0){
                            return "正在审核中";
                        }else if(d.status==1){
                            return "通过";
                        } else{
                            return "拒绝";
                        }
                    }}
                , {field: 'systatus', title: '系统审核结果', align: 'center',templet:function (d) {
                        if(d.systatus==0){
                            return "正在审核中";
                        }else if(d.systatus==1){
                            return "通过";
                        } else if(d.systatus==2){
                            return "拒绝";
                        }else{
                            return "";
                        }
                    }}
                ,{field: 'level', title: '申请类目', align: 'center',templet:function (d) {
                        if(d.level==1){
                            return "入党积极分子";
                        }else if(d.level==2){
                            return "预备党员";
                        } else{
                            return "正式党员";
                        }
                    }}

            ] ]
            //回调函数
            , done: function (res,curr, count) {
                if (curr > 1 && res.data.length == 0) {
                    var pageValue = curr -1;
                    tableIns.reload({
                        page:{curr:pageValue}
                    })
                }
            }
        });

        form.on("submit(doSearch)", function (data) {
            //表格数据重新加载
            console.log(data);
            tableIns.reload({
                where: data.field //额外的参数
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //关闭跳转页面
        });

        //监听
        table.on('toolbar(customerTable)', function (obj) {
            switch (obj.event) {
                //添加栏触发事件
                case 'addLevel1':
                    openAddCustomerWindowLevel1();//添加方法
                    break;
                case 'addLevel2':
                    openAddCustomerWindowLevel2();//添加方法
                    break;
                case 'addLevel3':
                    openAddCustomerWindowLevel3();//添加方法
                    break;
                case 'pay':
                    pay();//添加方法
                    break;


            }
        });




        var mainIndex;//弹出层的索引下标
        var url;//提交路径

        //弹出添加框函数
        function openAddCustomerWindowLevel1() {
            mainIndex = layer.open({
                type:1,
                title:"提交入党积极分子申请",
                area:["1000px","600px"],
                content:$("#addOrUpdateDiv"),//内容窗口
                success:function () {
                    //每次开启清空弹出框数据
                    $("#dataFrm")[0].reset();
                    $("#level").val(1);
                    url="/customer/addcustomer";
                }
            });
        }
        function openAddCustomerWindowLevel2() {
            mainIndex = layer.open({
                type:1,
                title:"提交预备党员申请",
                area:["1000px","600px"],
                content:$("#addOrUpdateDiv"),//内容窗口
                success:function () {
                    //每次开启清空弹出框数据
                    $("#dataFrm")[0].reset();
                    $("#level").val(2);
                    url="/customer/addcustomer";
                }
            });
        }
        function openAddCustomerWindowLevel3() {
            mainIndex = layer.open({
                type:1,
                title:"提交正式党员申请",
                area:["1000px","600px"],
                content:$("#addOrUpdateDiv"),//内容窗口
                success:function () {
                    //每次开启清空弹出框数据
                    $("#dataFrm")[0].reset();
                    $("#level").val(3);
                    url="/customer/addcustomer";
                }
            });
        }

        //监听添加和修改窗口的提交事件
        form.on("submit(doSubmit)", function (data) {
            //表格数据重新加载
            console.log(data);
            $.post(url,data.field,function (result) {
                //判断是否成功
                if (result.status){
                    //成功表格刷新
                    tableIns.reload();
                }
                //弹出是否成功消息
                layer.msg(result.message);
                //关闭窗口
                layer.close(mainIndex)
            },"json");
            return false; //关闭跳转页面
        });

        table.on("tool(customerTable)", function (obj) {
            var data =obj.data;
            switch (obj.event) {
                //修改数据
                case 'disagree':
                    disagreeCustomer(data);
                    break;
                case 'agree':
                    agreeCustomer(data);
                    break;
                case 'delete':
                    deleteCustomer(data);
                    break;
            }
        });

        //修改
        function agreeCustomer(data) {
            layer.confirm('是否通过这条数据吗?', {icon: 3, title: '提示'}, function (index) {
                $.post("/customer/agreeOne", {"id": data.custid}, function (result) {
                    if (result.status) {
                        //删除成功后刷新数据表格
                        tableIns.reload();
                    }
                    layer.msg(result.message);
                }, "json");
                layer.close(index);//关闭提示框
            });
        }

        function pay() {
            layer.confirm('是否确认付款50元?', {icon: 3, title: '提示'}, function (index) {
                $.post("/customer/pay", {}, function (result) {
                    if (result.status) {
                    }
                    layer.msg(result.message);
                }, "json");
                layer.close(index);//关闭提示框
            });
        }
        //修改
        function disagreeCustomer(data) {
            layer.confirm('是否拒绝这条数据吗?', {icon: 3, title: '提示'}, function (index) {
                $.post("/customer/disAgreeOne", {"id": data.custid}, function (result) {
                    if (result.status) {
                        //删除成功后刷新数据表格
                        tableIns.reload();
                    }
                    layer.msg(result.message);
                }, "json");
                layer.close(index);//关闭提示框
            });
        }
        //删除单条数据
        function deleteCustomer(data) {
            layer.confirm('是否要删除这条数据吗?', {icon: 3, title: '提示'}, function (index) {
                $.post("/customer/deleteOne", {"id": data.custid}, function (result) {
                    if (result.status) {
                        //删除成功后刷新数据表格
                        tableIns.reload();
                    }
                    layer.msg(result.message);
                }, "json");
                layer.close(index);//关闭提示框
            });
        }

    });
</script>
</body>
</html>